﻿using System;
using System.Collections.Generic;
using System.Text;
using Antu.WebControls;
using Antu.WorkFlowFactory;
using Antu.Core.Services;

namespace WebSys.UI.OfficeFlow
{
    public class WorkFlowWorkItem : MPPage
    {
        protected string ResServerPath = "";
        protected string strWIID = "";
        protected string strIID = "";
        protected string strSessionId = "";
        protected string wid = "";
        protected string ctlid = "";
        protected string ClientJs = "AntuOle.js";
        protected string docPath = "";
        protected string UserId
        {
            get { if (base.Page.Session["UserId"] != null) { return base.Page.Session["UserId"].ToString(); } else { return string.Empty; } }
            set { base.Page.Session["UserId"] = value; }
        }
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            InitControl();
        }
        private void InitControl()
        {
            string formname = Request["formname"];
            strWIID = Request["wiid"];
            strIID = Request["iid"];
            wid = wid = _FlowFactoryProvider.GetWidByIID(strIID);
            ctlid = Request["ctlid"];
            //strSessionId = "fd4040dd-7a00-448a-9208-73e0be44b33f";
            strSessionId = UserId;
            Antu.SystemLayer.Config configNew = new Antu.SystemLayer.Config(true);
            string IsNewVersion = configNew.GetAppSettingsValue("NewClientVersion");
            ResServerPath = System.Web.Configuration.WebConfigurationManager.AppSettings["NetoWs.service"];

            if (IsNewVersion == "1")
            {
                ClientJs = "AntuClient.js";
            }
            //老版本，并且不是删除事件的时候
            else if (Request["act"] != "DelWord")
            {
                //暂时先写在这里实现了来，林继平
                string sql = "select b.aid,b.ext_name from st_dynamic_resource a,st_attachment b " +
                       "Where a.res_value=b.aid and a.iid=" + strIID + " and a.path='" + formname + "'";
                if (!String.IsNullOrEmpty(formname) && Request["useDoc"] != "no")
                {
                    System.Data.DataTable dt = _FlowFactoryProvider.GetDT(sql);
                    if (dt.Rows.Count > 0)
                    {
                        string ext = dt.Rows[0]["ext_name"].ToString();
                        if (ext.ToLower() == ".doc" || ext.ToLower() == ".docx")
                        {
                            docPath = ResServerPath.Replace("Service.asmx?WSDL", "") + "/Attachment/OfficeHandle.aspx?step=" + ctlid + "&UserId=" + strSessionId + "&iid=" + strIID + "&aid=" + dt.Rows[0]["aid"].ToString();
                        }
                    }
                }
            }
            if (String.IsNullOrEmpty(strSessionId))
            {
                Response.Write("<script language=javascript>alert('用户Session为空无效，无法打开业务，请与管理员联系解决！');</script>");
                Response.End();
            }
        }
    }
}
